export default {
  namespaced:true,
  state :()=>({
    address:JSON.parse(uni.getStorageSync('address')||'{}'),
    token:uni.getStorageSync('token')||'',
    userInfo:JSON.parse(uni.getStorageSync('userInfo')||'{}'),
    redirectInfo:null
  }),
  mutations :{
    updateRedirectInfo(state,info){
      state.redirectInfo=info
    },
    updateAddress(state,address){
      state.address=address
      this.commit('user/saveStorageAddress')
    },
    updateuserInfo(state,userInfo){
      state.userInfo=userInfo
      this.commit('user/saveStorageuserInfo')
    },
    updateToken(state,token){
      state.token=token
      this.commit('user/saveStorageToken')
    },
    saveStorageAddress(state){
      uni.setStorageSync('address',JSON.stringify(state.address))
    },
    saveStorageuserInfo(state){
      uni.setStorageSync('userInfo',JSON.stringify(state.userInfo))
    },
    saveStorageToken(state){
      uni.setStorageSync('token',JSON.stringify(state.token))
    }
  },
  getters :{
    getAddressName(state){
      if(!state.address) return ''
      return state.address.provinceName+state.address.cityName+state.address.countyName+state.address.detailInfo
    }
  }
}